module ResultState where

import qualified Control.Monad.Trans.State as State
import qualified Control.Monad.Error as Error
import Control.Monad
import Control.Monad.Trans
import Result
import Accessor


type ResultState s e a = State.StateT s (Result e) a


run :: ResultState s e a -> s -> Result e (a, s)
------------------------------------------------
run = State.runStateT


failure :: e -> ResultState s e a
---------------------------------
failure = Error.throwError


rollback :: ResultState s e a -> (e -> ResultState s e a) -> ResultState s e a
------------------------------------------------------------------------------
rollback try handler = Error.catchError try handler
